package com.example.thread.d9CompletableFuture2;

import java.util.StringJoiner;
import java.util.concurrent.TimeUnit;

public class CommonUtils {

    public static String readFile(String pathToFile) {
        try {
            return pathToFile;
        } catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }
    public static void sleepMillis(long millis) {
        try {
            TimeUnit.MICROSECONDS.sleep(millis);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void sleepSecond(int seconds) {
        try {
            TimeUnit.SECONDS.sleep(seconds);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void printThreadLog(String message) {
        String result = new StringJoiner(" | ")
                .add(String.valueOf(System.currentTimeMillis()))
                .add(String.format("%2d",Thread.currentThread().getId()))
                .add(String.valueOf(Thread.currentThread().getName()))
                .add(message)
                .toString();
        System.out.println(result);
    }

}
